<template>
	<view>
		<u-tabs-swiper ref="tabs" :current='current' :list="list" :is-scroll="false" @change='change'></u-tabs-swiper>
		<view class="u-p-20">
			<view class="bs_CCCCCC u-b-r-10 u-p-20 u-m-t-20" v-for="(item,index) in array" :key="index">
				<view class="u-flex u-row-between">
					<view class="">
						<view class="cl_1C1C1CFF u-font-28 u-p-6 u-flex">
							<view class="u-weight ">{{item.title}}</view>
							<view v-if="item.limit_money" class="u-m-l-20 u-font-20"
								style="padding: 6rpx 10rpx;color: #FB473C; border: 1rpx solid #FB473C;">满{{item.limit_money}}元可用</view>
						</view>
						<view class="u-p-6 u-font-20 cl_454545FF">{{item.type_text}}</view>
						<view class="u-p-6 u-font-20 cl_454545FF">有效期：{{item.use_start_date}}--{{item.use_end_date}}</view>
					</view>
					<view class="cl_FC3533FF">
						<text class="u-font-26">￥</text>
						<text class="u-font-40">{{item.use_money}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 加载更多 -->
		<u-loadmore :status="status" icon-type="circle" margin-top="20" margin-bottom="20" />
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 切换顶部栏
				current: '0',
				list: [{
					name: '待使用'
				}, {
					name: '已使用'
				}, {
					name: '已失效'
				}],
				params:{
					page:1,
					page_size:10,
					status:'0'
				},
				array:[],
				status: 'loadmore',
			}
		},
		onLoad() {
			this.clear()
			this.massage()
		},
		// 下拉到底事件
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			if (this.list.length >= 20) {
				this.massage();
			}
		},
		methods: {
			clear(){
				this.array=[]
				this.params.page=1
			},
			massage(){
				this.$api.my_card(this.params,res=>{
					if (res.data.code == 1) {
						if (res.data.data.rows.length < 20) {
							this.status = 'nomore';
						} else {
							this.params.page = this.params.page + 1;
							this.status = 'loadmore';
						}
						this.array = this.array.concat(res.data.data.rows);
						uni.stopPullDownRefresh();
					}
				})
			},
			// 更换标题
			change(index) {
				this.current = index
				this.params.status=this.current
				this.clear()
				this.massage()
			},
		}
	}
</script>

<style scoped>
	.one {
		width: 674rpx;
		height: 260rpx;
		background: url('https://www.sqkjkj.vip/wxImg/common/collectCoupons/img5.png') no-repeat;
		background-size: 100% 100%;
	}

	.ones {
		width: 503rpx;
		height: 596rpx;
		background: url('https://www.sqkjkj.vip/wxImg/mybag/img5.png') no-repeat;
		background-size: 100% 100%;
	}

	.ban {
		position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, .4);
	}

	.error {
		width: 74rpx;
		height: 160rpx;
		background: url('https://www.sqkjkj.vip/wxImg/common/home/img12.png') no-repeat;
		background-size: 100% 100%;
	}
</style>
